m.controller("showAllCtrl",function($rootScope,$scope,$location) {
	
$scope.getLoggedUser = function(){
		
		if($rootScope.userOfLoger == null || $rootScope.userOfLoger ==''){
			$.ajax({
	            type:"POST",
	            url:"/login/getSession",
	            contentType:"application/x-www-form-urlencoded",
	            dataType:"json",
	            success:function(data){
	                if(data.value!=null){
	                	$rootScope.userOfLoger = data.value;
	                	
	                }else{
	                	$rootScope.userOfLoger = null;
	                }

	            	$scope.init();//页面初始化
            		 $scope.$apply();
	            }
			});
		}
		
		
		
	}
	
	
$scope.init = function(){
			$scope.commodity = null;
			$scope.deleteId = 0;
			$scope.type = $rootScope.getParam("type");
			
			if($scope.type=="1" && $scope.userOfLoger.name == "buyer"){
				$.ajax({
		            type:"POST",
		            url:"/commodity/getNoSelledComm",
		            contentType:"application/x-www-form-urlencoded",
		            dataType:"json",
		            success:function(data){
		            	$scope.$apply(function(){
		                    
		                    $scope.commodity = data.value;
		                   
		                    
		                });
		            }
				});
			}else{
				$.ajax({
		            type:"POST",
		            url:"/commodity/getAllComm",
		            contentType:"application/x-www-form-urlencoded",
		            dataType:"json",
		            success:function(data){
		            	$scope.$apply(function(){
		                    
		                    $scope.commodity = data.value;
		                    
		                    })
		                    
		                }
		            
				});
			}
	
	
			
		
	}

	//删除商品模态框
	$scope.deleteCommModal = function(data){
		$scope.deleteId = data;
		$("#modalid-add-delete").modal("toggle");
	}

	//删除商品
	$scope.deleteComm = function(data){
		$.ajax({
            type:"POST",
            url:"/commodity/deleteComm",
            contentType:"application/x-www-form-urlencoded",
            data:{"id":$scope.deleteId},
            dataType:"json",
            success:function(data){
                if(data.success == true){
                	alert("删除成功");
                }else{
                	alert("错误");
                }

            	
                $scope.$apply();
                $scope.init();
            }
		});
	}
	$scope.getLoggedUser();
});